﻿package  {
	import flash.display.DisplayObject;
	import flash.geom.Point;
	
	public class Util {

		public static function safeRemove(obj:DisplayObject):void{
			if (obj != null){
				if (obj.parent != null){
					obj.parent.removeChild(obj);
				}
			}
		}
		
		public static function copyArray(ary1:Array):Array{
			var ary2:Array = [];
			
			for (var i:int = 0; i < ary1.length; i++){
				ary2[i] = ary1[i];
			}
			
			return ary2;
		}
		
		public static function getDistance(mc1:DisplayObject, mc2:DisplayObject):Number{
			var p1:Point = new Point(mc1.x, mc1.y);
			var p2:Point = new Point(mc2.x, mc2.y);
			
			return (p2.y-p1.y)/(p2.x-p1.x);
		}
		
		public static function addZeros(num:int, len:int):String{
			var str:String = ""+num;
			
			while (str.length < len){
				str = "0"+str;
			}
			
			return str;
		}

	}
	
}
